package com.youlu.campus.web.user.controller;

import com.youlu.campus.common.base.QResult;
import com.youlu.campus.entity.UserPO;
import com.youlu.campus.web.common.base.RequestContext;
import com.youlu.campus.web.user.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户详情
 *
 * @author: su
 * @date: 2025/10/15
 */
@Slf4j
@RestController
public class UserInfoController {

    @Autowired
    private UserService userService;


    /**
     * 获取用户详情
     *
     * @return
     */
    @GetMapping("/user/info")
    public QResult userInfo() {
        UserPO userPO = userService.queryUserById(RequestContext.getUserId());
        return QResult.success(userPO);
    }

    /**
     * 更新用户详情
     *
     * @return
     */
    @PostMapping("/user/update")
    public QResult updateUserInfo(@RequestBody UserPO userPO) {
        userPO.setId(RequestContext.getUserId());
        userService.updateUserInfo(userPO);
        return QResult.success(userPO);
    }

}